//
//  AppDelegate.m
//  UiView
//
//  Created by 成都千锋 on 15/9/8.
//  Copyright (c) 2015年 ZhangYe. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
//UIView是所有视图的父类，UIView的属性和方法，就是所有视图的属性和方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    //1.创建view
    UIView *view=[[UIView alloc]init];
    //2. 位置尺寸
    view.frame=CGRectMake(self.window.bounds.size.width/2-50, 100, 100, 100);
    NSLog(@"%f>>>%f",view.center.x,view.center.y);
    //3.背景颜色 背景图片
    view.backgroundColor = [UIColor yellowColor];
    //注意二次设置背景颜色会覆盖掉前一次的颜色
    view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"10"]];
    //4.偏移
    //view.transform=CGAffineTransformMakeTranslation(100, 100);
    //5.旋转
    //M_PI_2为旋转了90度
    view.transform=CGAffineTransformMakeRotation(M_PI_2);
    //6.透明度
    view.alpha=1;
    [self.window addSubview:view];
    //7.是否隐藏
    view.hidden=NO;
    //8.裁剪 只有正方形才可裁剪为一个圆 若裁剪边长的一半则为一个圆
    view.layer.masksToBounds=YES;
    view.layer.cornerRadius=50;
    
    view.tag=100;
    //9.UIView动画效果 UIView动画只能修改关于坐标系的属性，以及色彩和透明度。
    //经过几秒完成block里的内容
//    [UIView animateWithDuration:5 animations:^{
//        view.center=CGPointMake(250, 300);
//        view.alpha=0;
//    }];
    NSTimer *timer=[[NSTimer alloc]init];
    _a=2;
    timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(goToRun:) userInfo:nil repeats:YES];
    [timer fire];
    if (_a==10) {
        [timer invalidate];
    }
    //把View2拿到最上面来
    //[self.window bringSubviewToFront:view2];
    //把view3放到最下面去
    // [self.window sendSubviewToBack:view3];
    //把View插入到某个位置
    //[self.window insertSubview:view4 atIndex:0];
    //把View4放在view1的上面
    //[self.window insertSubview:view4 aboveSubview:view1];
    //把View4放在view1的下面
    //[self.window insertSubview:view4 belowSubview:view1];
    //View交换图层
    //[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    return YES;
}
-(void)goToRun:(NSTimer*)timer{
     _a++;
    UIView *view=(UIView *)[self.window viewWithTag:100];
    [UIView animateWithDuration:3 animations:^{
        view.transform=CGAffineTransformMakeRotation(M_PI_4*_a);
    }];
  

}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
